<!-- 找回密码 -->
<template>
	<view class="form">
		<u-form ref="uForm">
			<view>
				<u-form-item border="true" label="用户名:" label-width="140">
					<u-input v-model="userName" id="请输入用户名" />
				</u-form-item>
				<u-form-item border="true" label="教工号:" label-width="140">
					<u-input v-model="uid" placeholder="请输入教工号" />
				</u-form-item>
				<u-form-item border="true" label="旧密码:" label-width="140">
					<u-input v-model="oldPassword" type="password" placeholder="请输入原始密码" />
				</u-form-item>
				<u-form-item border="true" label="新密码:" label-width="140">
					<u-input v-model="password" type="password" placeholder="请输入新密码" />
				</u-form-item>
				<u-form-item border="true" label="确认密码:" label-width="140">
					<u-input v-model="rePassword" type="password" placeholder="请确认密码" />
				</u-form-item>
			</view>
			<u-button type="primary" style class="u-margin-top-40" @click="lookup">修改密码</u-button>
		</u-form>
	</view>
</template>

<script>
	import request from '../../../util/request.js'
	import api from '../../../util/api.js'
	export default {
		data() {
			return {
				oldPassword: '',
				password: '',
				rePassword: '',
				code: {
					text: '获取验证码',
					status: false,
					value: ''
				},
				uid: '', //教工号
				userName: ''
			}
		},
		methods: {
			lookup: function() {
				if (this.password == "") {
					uni.showToast({
						icon: 'none',
						title: '新密码不能为空'
					})
					return;
				}
				if (this.password != this.rePassword) {
					uni.showToast({
						icon: 'none',
						title: '新密码与重复密码不一致'
					})
					return;
				}
				request.post(api.updatePw, {
					username: this.userName,
					uid: this.uid,
					oldPassword: this.oldPassword,
					password: this.password,
					rePassword: this.rePassword
				}).then(response => {
					console.log('abc=', response);
					if (response.data.status == 1) {
						uni.showToast({
							icon: 'none',
							title: '修改密码成功',
						})
					} else {
						uni.showToast({
							icon: 'none',
							title: '修改密码失败请与管理员联系'
						})
					}
				}).catch(ex => {
					uni.showToast({
						icon: 'none',
						title: '请求失败，请稍后再试'
					})
				})
			}
		}
	}
</script>

<style>
	.form {
		background-color: #FFFFFF;
		padding: 26rpx;
	}

	.code-btn {
		background: none;
		font-size: 28rpx;
		color: #845708;
		border-left: 1rpx solid #d0b17b;
		border-radius: 0;
		height: 42rpx;
		width: 190rpx;
		padding: 0;
	}

	.cu-btn {
		position: relative;
		border: 0upx;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;
		padding: 0 30upx;
		font-size: 28upx;
		height: 64upx;
		line-height: 1;
		text-align: center;
		text-decoration: none;
		overflow: visible;
		margin-left: initial;
		transform: translate(0upx, 0upx);
		margin-right: initial;
	}
</style>
